@extends('mbcore.baseadmin::layout.iframe')
@section('title', '账号激活')

@section('content')
    <div class="wrapper wrapper-content">
        <div class="row">
            <div class="col-sm-12">
                <div class="middle-box text-center animated fadeInRightBig">
                    <h3 class="font-bold">激活账号</h3>

                    <div class="error-desc">
                        您好，您的账号未激活，请先激活您的账号，否则将影响系统的使用
                        <br/><button  class="btn btn-primary m-t activation">去激活</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
@stop

@push('startcss')
    <link href="{{ config('mbcore_baseadmin.baseadmin_assets_path')}}/css/plugins/sweetalert/sweetalert.css" rel="stylesheet">
@endpush

@section('myscript')
    <script src="{{ config('mbcore_baseadmin.baseadmin_assets_path')}}/js/plugins/sweetalert/sweetalert.min.js"></script>
    <script>
        $('body').on('click','.activation',function(){
            activation();
        })

        function activation(){
            swal({
                title: "账号激活",
                inputPlaceholder: "请输入账号激活码",
                type: "input",
                showCancelButton: false,
                confirmButtonColor: "#DD6B55",
                confirmButtonText: "激活",
                closeOnConfirm: false
            }, function (inputValue) {
                var url = '{{ route("v1.admin.activateAccount") }}'
                $.ajax({
                    type: "POST",
                    url: url,
                    data:{
                        'activation_code':inputValue,
                    },
                    success: function(data){
                        console.log(data);
                        console.log(data.code);
                        if (data.code == 200){
                            swal({
                                title: "账号激活成功",
                                text: "恭喜，您的账号已激活，可以开始使用系统了",
                                type: "success",
                                showCancelButton: false,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "进入系统",
                                closeOnConfirm: false,
                                timer:5000,
                            },function(){
                                window.location.href = '{{ route("admin.homepage.index") }}'//data.result.url
                            })
                        }else{
                            swal({
                                title: "账号激活失败",
                                text: data.msg,
                                type: "error",
                                showCancelButton: false,
                                confirmButtonColor: "#DD6B55",
                                confirmButtonText: "重新激活",
                                closeOnConfirm: false,
                            },function (){
                                activation();
                            })
                        }
                    }
                });
            })
        }
        jQuery.extend({
            "activateAccount": function () {
                swal({
                    title: "您的账号还未激活",
                    inputPlaceholder: "请输入激活码，已激活账号，否则系统无法使用",
                    type: "input",
                    showCancelButton: false,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "激活",
                    closeOnConfirm: false
                }, function (inputValue) {
                    var url = '{{ route("v1.admin.activateAccount") }}'
                    $.ajax({
                        type: "POST",
                        url: url,
                        data:{
                            'activation_code':inputValue,
                        },
                        success: function(data){
                            console.log(data);
                            console.log(data.code);
                            if (data.code == 200){
                                // swal("操作完成",'账号已激活', "success");
                                swal({
                                    title: "操作完成",
                                    text: "账号已激活",
                                    type: "success",
                                    showCancelButton: false,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "关闭",
                                    closeOnConfirm: false,
                                    timer:3000,
                                })
                            }else{
                                swal({
                                    title: "账号激活失败",
                                    text: data.msg,
                                    type: "error",
                                    showCancelButton: false,
                                    confirmButtonColor: "#DD6B55",
                                    confirmButtonText: "重新激活",
                                    closeOnConfirm: false,
                                },function (){
                                    show1();
                                })
                            }
                        }
                    });
                })
                return true;
            },
        });
        // $.activateAccount();
    </script>
@stop
